package org.mall.modules.promotion.controller.users;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.mall.common.api.vo.CommonResult;
import org.mall.common.constant.CommonStatusEnum;
import org.mall.convert.promotion.admin.BannerConvert;
import org.mall.modules.pojo.promotion.bo.BannerBO;
import org.mall.modules.pojo.promotion.users.UsersBannerVO;
import org.mall.modules.promotion.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Comparator;
import java.util.List;

@RestController
@RequestMapping("/users/banner")
@Api("Banner 模块")
public class UsersBannerController {

   @Autowired
    private BannerService bannerService;
    @GetMapping("/list")
    @ApiOperation("获得所有 Banner 列表")
    public CommonResult<List<UsersBannerVO>> list() {
        // 查询 Banner 列表
        List<BannerBO> result = bannerService.getBannerListByStatusAndType(CommonStatusEnum.ENABLE.getValue(),2);
        // 排序，按照 sort 升序
        result.sort(Comparator.comparing(BannerBO::getSort));
        // 返回
        return CommonResult.success(BannerConvert.USERS.convertList(result));
    }
    @GetMapping("/getShopBanner")
    @ApiOperation("获得所有 Banner 列表")
    public CommonResult<List<UsersBannerVO>> getShopBanner() {
        // 查询 Banner 列表
        List<BannerBO> result = bannerService.getBannerListByStatusAndType(CommonStatusEnum.ENABLE.getValue(),2);
        // 排序，按照 sort 升序
        result.sort(Comparator.comparing(BannerBO::getSort));
        // 返回
        return CommonResult.success(BannerConvert.USERS.convertList(result));
    }

    @GetMapping("/adList")
    @ApiOperation("获得所有 adList 列表")
    public CommonResult<List<UsersBannerVO>> adList() {
        // 查询 Banner 列表
        List<BannerBO> result = bannerService.getBannerListByStatusAndType(CommonStatusEnum.ENABLE.getValue(),3);
        // 排序，按照 sort 升序
        result.sort(Comparator.comparing(BannerBO::getSort));
        // 返回
        return CommonResult.success(BannerConvert.USERS.convertList(result));
    }
}
